/**
*      author: Y_Yao
*      created: 2024-11-11 21:56:50
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int n,m,v;
int ltor[N],rtol[N],sum[N],a[N];

void solve()
{
    cin >> n >> m >> v;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];
    }

    ltor[0] = 0;
    int count = 0;
    for(int i = 1;i <= n;i++)
    {
        count += a[i];
        if(count >= v)
        {
            ltor[i] = ltor[i-1] + 1;
            count = 0;
        }
        else
        {
            ltor[i] = ltor[i-1];
        }
    }

    count = 0;
    rtol[n+1] = 0;
    for(int i = n;i >= 0;i--)
    {
        count += a[i];
        if(count >= v)
        {
            rtol[i] = rtol[i+1] + 1;
            count = 0;
        }
        else
        {
            rtol[i] = rtol[i+1];
        }
    }

    int ret = -1;
    for(int i = 0,j = 1;i <= n;i++,j = max(j,i+1))
    {
        int need = m - ltor[i];
        while(j <= n + 1 && rtol[j] >= need) j++;
        j--;
        if(rtol[j] >= need) ret = max(ret,sum[j - 1] - sum[i]);
    }

    cout << ret << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}